/*
 * File Name：CheckWorklvAdapter.java
 * Copyright：Copyright 2008-2015 CiWong.Inc. All Rights Reserved.
 * Description： CheckWorklvAdapter.java
 * Modify By：pla-gysu
 * Modify Date：2015年1月13日
 * Modify Type：Add
 */
package com.ciwong.epaper.modules.epaper.adapter;

import com.ciwong.epaper.R;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;


/**
 * 答题卡适配器
 * 
 * @author pla-gysu
 * @version ciwong v.1.0 2015年1月27日
 * @since ciwong v.1.0
 */
public class AnswerCardAdapter extends BaseAdapter
{
    private int currSelected = 0;

    private Activity activity;

    private List<String> quesNoList;

    public AnswerCardAdapter(Activity activity, List<String> quesNoList)
    {
        this.activity = activity;
        this.quesNoList = quesNoList;
    }

    public int getCurrSelected()
    {
        return currSelected;
    }

    public void setCurrSelected(int currSelected)
    {
        this.currSelected = currSelected;
    }

    private static class ViewHolder
    {
        TextView quesNo;// 题号
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;

        if (convertView == null)
        {
            holder = new ViewHolder();
            convertView = View.inflate(activity, R.layout.item_answer_card,
                    null);
            holder.quesNo = (TextView) convertView
                    .findViewById(R.id.tv_ques_no);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.quesNo.setTextColor(activity.getResources().getColor(
                currSelected == position ? R.color.blue
                        : R.color.answer_card_item_border));

        holder.quesNo.setText(quesNoList.get(position));

        holder.quesNo
                .setBackgroundResource(currSelected == position ? R.drawable.shape_answer_card_pressed
                        : R.drawable.shape_answer_card);

        return convertView;
    }

    @Override
    public int getCount()
    {
        return quesNoList.size();
    }

    @Override
    public Object getItem(int position)
    {
        return quesNoList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }
}
